#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 505;

int n, m;
char a[N][N];
int dis[N][N], vis[N][N];
int dx[] = {-1, -1, 1, 1};
int dy[] = {-1, 1, -1, 1};
int get_dis(int x, int y, int xx, int yy) {
  int r = max(x, xx), c = max(y, yy);
  char ch = a[r][c];
  if (((r + c) & 1) && ch == '/') return 0;
  if (((r + c) & 1) == 0 && ch == '\\') return 0;
  return 1;
}
int bfs() {
  memset(dis, 0x3f, sizeof(dis));
  deque<pii> q;
  q.push_back(pii(0, 0));
  dis[0][0] = 0;
  while (q.size()) {
    pii now = q.front();
    q.pop_front();
    int x = now.first, y = now.second;
    if (x == n && y == m) return dis[x][y];
    if (vis[x][y]) continue;
    vis[x][y] = 1;
    rep(i, 0, 3) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx < 0 || xx > n || yy < 0 || yy > m) continue;
      int w = get_dis(x, y, xx, yy);
      if (dis[xx][yy] > dis[x][y] + w) {
        dis[xx][yy] = dis[x][y] + w;
        if (w == 0)
          q.push_front(pii(xx, yy));
        else
          q.push_back(pii(xx, yy));
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) rep(j, 1, m) cin >> a[i][j];
  if ((n + m) & 1) {
    cout << "NO SOLUTION";
    return 0;
  }
  cout << bfs();
  return 0;
}